package com.mycompany.project.server;

import java.util.ArrayList;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import marketplace.componente.transacciones.SistemaTransaccionesRemote;
import marketplace.objects.TransaccionBO;

import com.mycompany.project.client.TransaccionesService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class TransaccionesServiceImpl extends RemoteServiceServlet implements TransaccionesService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void registrarTransacciones(ArrayList<TransaccionBO> transacciones) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			SistemaTransaccionesRemote adminT = (SistemaTransaccionesRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteTransacciones/SistemaTransacciones");
			adminT.registrarTransacciones(transacciones);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		
	}

	@Override
	public ArrayList<TransaccionBO> consultarTransaccionesCliente(
			String loginCliente) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			SistemaTransaccionesRemote adminT = (SistemaTransaccionesRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteTransacciones/SistemaTransacciones");
			return adminT.consultarTransaccionesCliente(loginCliente);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}

	@Override
	public ArrayList<TransaccionBO> consultarTransaccionesProveedor(
			String loginProveedor) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			SistemaTransaccionesRemote adminT = (SistemaTransaccionesRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteTransacciones/SistemaTransacciones");
			return adminT.consultarTransaccionesProveedor(loginProveedor);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}

	@Override
	public TransaccionBO consultarTransaccion(long id) {
		// TODO Auto-generated method stub
		Context ctx;
		try {
			ctx = new InitialContext();
			//NamingEnumeration<NameClassPair> stuff = ctx.list("");
			//while(stuff.hasMore()){
			//NameClassPair na = stuff.next();
			//System.out.println(na.getClassName()+" "+na.getName());
			//}
			SistemaTransaccionesRemote adminT = (SistemaTransaccionesRemote) ctx.lookup("java:global/EnterpriseMarketplaceProject/ComponenteTransacciones/SistemaTransacciones");
			return adminT.consultarTransaccion(id);
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("aqui fue");
			e.printStackTrace();
			
		}
		return null;
	}
}
